using System.Text.Json.Serialization;
using EasyDDD.AdminModule.Host.WebAPI.ActionFilter;
using EasyDDD.Application;
using EasyDDD.TemplateModule.Application;
using Scalar.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
// Add services to the container.

builder.Services.AddControllers(c =>
{
    c.Filters.Add<BusinessExceptionFilter>();
    c.Filters.Add<PureAdminResponeActionFilter>();

}).AddJsonOptions(options =>
{
    options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
    //options.JsonSerializerOptions.WriteIndented = true; 

});

// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddCors(options =>
{
    options.AddDefaultPolicy(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
});

builder.Services.AddTemplateModule(builder.Configuration);
builder.Services.AddAutoMapper(typeof(EasyDDD.TemplateModule.WebAPI.Controllers.AutoMapperProfile));

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    //app.MapOpenApi();
}

app.MapOpenApi();
app.MapScalarApiReference();

app.UseSwagger();
app.UseSwaggerUI();
//app.UseSwaggerUI(options =>
//{
//    options.SwaggerEndpoint("/openapi/v1.json", "v1");
//});

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
